import { createRouter, createWebHashHistory } from 'vue-router'
// import Home from '@/views/Home.vue';
// import Register from '@/views/Register.vue';
// import Category from "@/views/Category.vue";
// import Address from '@/views/Address.vue';
// import Login from '@/views/Login.vue';
// import Cart from '@/views/Cart.vue';
// import City from '@/views/City.vue';
// import Detail from '@/views/Detail.vue';
// import NotFound from '@/views/NotFound.vue';
// import Search from '@/views/Search.vue';
// import Order from '@/views/Order.vue';
// import User from '@/views/User.vue';
// import Info from "@/views/Info.vue";
const routes = [
  { path: '/', component: () => import('@/views/ying/Home.vue') },
  {
    path: '/register',
    component: () => import('@/views/liao/Register.vue')
  },
  {
    path: '/address',
    component: () => import('@/views/liang/Address.vue'),
    meta: {
      needCheckLogin: true
    }
  },
  {
    path: '/category',
    component: () => import('@/views/huang/Category.vue')
  },
  { path: '/login', component: () => import('@/views/liao/Login.vue') },
  {
    path: '/cart',
    component: () => import('@/views/huang/Cart.vue'),
    meta: {
      needCheckLogin: true
    }
  },
  { path: '/city', component: () => import('@/views/City.vue') },
  { path: '/detail/:id', component: () => import('@/views/he/Detail.vue') },
  {
    path: '/pay',
    component: () => import('@/views/feng/Pay.vue')
  },

  {
    path: '/search',
    component: () => import('@/views/Search.vue'),

  },
  {
    path: '/order',
    component: () => import('@/views/feng/Order.vue'),
    meta: {
      needCheckLogin: true
    }
  },
  {
    path: '/user',
    component: () => import('@/views/liao/User.vue'),
    meta: {
      needCheckLogin: true
    },
  },
  {
    path: '/info',
    component: () => import('@/views/liao/Info.vue'),
    meta: {
      needCheckLogin: true
    }
  },
  { path: '/:pathMatch(.*)*', component: () => import('@/views/NotFound.vue') }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes as any
})

// // 全局路由守卫
// router.beforeEach(to => {
//   // to:去到的路由信息对象
//   if (to.meta.needCheckLogin) {
//     // console.log('需要检查登录状态');
//     if (localStorage.getItem('token') && localStorage.getItem('userid')) {
//       return true;
//     } else {
//       router.push('/login')
//       return false;
//     }
//   } else {
//     // console.log("不需要检查登录状态");
//     return true;
//   }
// })
export default router;